home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -screenplay- / otherstuff / f1gplib_dev / examples / test.c < prev    next >
C/C++ Source or Header  |  1999-12-06  |  3KB  |  111 lines

  1. /*******************************************************************
  2. ** Simple example of using "f1gp.library"
  3. */
  4. #include <exec/types.h>
  5. #include <dos/dos.h>
  6. #include <proto/exec.h>
  7. #include <proto/f1gp.h>
  8. #include <proto/alib.h>
  9. #include <libraries/f1gp.h>
  10.  
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13.  
  14. struct F1GPBase *F1GPBase;
  15. struct MsgPort *F1GPPort;
  16.  
  17.  
  18. VOID CleanPort(struct MsgPort *msgport)
  19. {
  20.    struct Message *msg;
  21.    while (msg = GetMsg(msgport)) ReplyMsg(msg);
  22. }
  23.  
  24. BOOL HandleF1GPMessages(VOID)
  25. {
  26.    struct F1GPMessage *msg;
  27.    BOOL running = TRUE;
  28.  
  29.    while (msg = (struct F1GPMessage *)GetMsg(F1GPPort)) {
  30.       switch (msg->EventType) {
  31.          case F1GPEVENT_QUITGAME:
  32.             printf("F1GP has exited (F1GPEVENT_QUITGAME)\n");
  33.             running = FALSE;
  34.             break;
  35.          case F1GPEVENT_EXITCOCKPIT:
  36.             printf("F1GP has returned to menu system (F1GPEVENT_EXITCOCKPIT)\n");
  37.             break;
  38.       }
  39.       ReplyMsg((struct Message *)msg);
  40.    }
  41.  
  42.    return(running);
  43. }
  44.  
  45. int main(int argc, char **argv)
  46. {
  47.    APTR f1gpnotify;
  48.    int i;
  49.    ULONG sigr,sig_f1gp;
  50.    BOOL running = TRUE;
  51.  
  52.    if (F1GPBase = (struct F1GPBase *)OpenLibrary("f1gp.library",36)) {
  53.       if (F1GPPort = CreatePort(NULL,0)) {
  54.  
  55.          /*********************
  56.          *** Initialisation ***
  57.          *********************/
  58.  
  59.          sig_f1gp = 1L << F1GPPort->mp_SigBit;
  60.          if (f1gpnotify = f1gpRequestNotification(F1GPPort,F1GPEVENT_QUITGAME | F1GPEVENT_EXITCOCKPIT)) {
  61.  
  62.             /****************
  63.             *** Main code ***
  64.             ****************/
  65.  
  66.             /* Detect if F1GP is currently running or not - IMPORTANT: this call
  67.                will also automatically install all relevant patches */
  68.             if (f1gpDetect()) {
  69.                for (i=0;i<4;i++) printf("Hunk %d: 0x%08x\n",i,F1GPBase->HunkStart[i]);
  70.  
  71.                printf("F1GP version: %d (see libraries/f1gp.h)\n",F1GPBase->F1GPType);
  72.                printf("Waiting until F1GP quits... (Press Ctrl-C to abort)\n");
  73.  
  74.                /* Wait for F1GP events of Ctrl-C */
  75.                while (running) {
  76.                   sigr = Wait(sig_f1gp | SIGBREAKF_CTRL_C);
  77.                   if (sigr & sig_f1gp)         running = HandleF1GPMessages();
  78.                   if (sigr & SIGBREAKF_CTRL_C) running = FALSE;
  79.              }
  80.  
  81.                printf("Exiting...\n");
  82.             }
  83.             else {
  84.                printf("F1GP not in memory - won't bother to wait, bye!\n");
  85.             }
  86.  
  87.             /*************************
  88.             *** Cleanup & Shutdown ***
  89.             *************************/
  90.  
  91.             f1gpStopNotification(f1gpnotify);
  92.      }
  93.          else {
  94.             printf("f1gpRequestNotification() failed\n");
  95.      }
  96.          CleanPort(F1GPPort);
  97.          DeletePort(F1GPPort);
  98.  
  99.       }
  100.       else {
  101.          printf("Unable to create message port\n");
  102.       }
  103.       CloseLibrary((struct Library *)F1GPBase);
  104.    }
  105.    else {
  106.       printf("Unable to open f1gp.library\n");
  107.    }
  108.  
  109.    return(0);
  110. }
  111.